package com.itheima.inner.test5;

public class Test {
    public static void main(String[] args) {
    /*    Animal a= new Dog();
        a.drink();
        a.eat();*/
        //局部内部类
        //创建了子类 重写了方法 创建子类对象
   /*     class Dog extends Animal{
            @Override
            void eat() {
                System.out.println("狗吃肉");
            }
        }
        Dog dog = new Dog();
        dog.eat();
        dog.drink();*/
        //匿名内部类
        Animal a = new Animal() {
            @Override
            void eat() {
                System.out.println("狗吃肉");
            }
        };// 创建了子类,  重写了方法 创建了子类的对象
        System.out.println(a);
        a.eat();
        a.drink();
    }

}

abstract class Animal {
    public void drink() {
        System.out.println("喝水");
    }

    abstract void eat();
}
/*
class Dog extends Animal{

    @Override
    void eat() {
        System.out.println("狗吃肉");
    }
}*/
